package com.shengsiyuan.netty.sixthexample.server;

import com.shengsiyuan.netty.sixthexample.StuffInfo;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

import static java.lang.System.out;

public class MyServerHandler extends SimpleChannelInboundHandler<StuffInfo.MyMessage> {


    @Override
    protected void channelRead0(ChannelHandlerContext ctx, StuffInfo.MyMessage msg) throws Exception {

        StuffInfo.MyMessage.DataType dataType = msg.getDataType();

        if (dataType == StuffInfo.MyMessage.DataType.PersonType) {
            out.println("person's name:" + msg.getPerson().getName());
        }

        if (dataType == StuffInfo.MyMessage.DataType.DogType) {
            out.println("dog's name:" + msg.getDog().getName());
        }

        if (dataType == StuffInfo.MyMessage.DataType.CatType) {
            out.println("cat's name:" + msg.getCat().getName());
        }
    }

}
